package servlet;

import entity.Rent;
import service.RentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddServlet")
public class AddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        RentService service = new RentService();
        Rent rent = new Rent();
        String userName = request.getParameter("userName");
        String carNum = request.getParameter("carNum");
        String maturityDate = request.getParameter("maturityDate");
        rent.setUserName(userName);
        rent.setCarNum(carNum);
        rent.setStatus(0);
        rent.setMaturityDate(maturityDate);
        int count = service.add(rent);
        if (count>0){
            request.setAttribute("info","添加成功！");
        }else {
            request.setAttribute("info","添加失败！");
        }
        request.getRequestDispatcher("ListServlet").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        super.doPost(request,response);
    }
}
